using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleCalendarReminder
{
    /// <summary>
    /// A class which provides static methods for GoogleCalendarReminder.WhenWrapper objects.
    /// </summary>
    public class WhenCalculator
    {
        /// <summary>
        /// Determines if a GoogleCalendarReminder.WhenWrapper object represents this moment
        /// in time down to the minute.
        /// </summary>
        /// <param name="when">The object to analyze.</param>
        /// <returns>true if the object represents this moment in time; false otherwise.</returns>
        public static bool IsReminderNow(WhenWrapper when, DateTime dateTime)
        {
            foreach (ReminderWrapper reminder in when.Reminders)
            {
                DateTime reminderTime = when.StartTime.Subtract(new TimeSpan(0, reminder.Minutes, 0));

                if (Properties.Settings.Default.ValidReminders.Contains(reminder.Method) &&
                    dateTime.Minute.Equals(reminderTime.Minute) &&
                    dateTime.Hour.Equals(reminderTime.Hour) &&
                    dateTime.Day.Equals(reminderTime.Day) &&
                    dateTime.Month.Equals(reminderTime.Month) &&
                    dateTime.Year.Equals(reminderTime.Year))
                {
                    return true;
                }
            }

            return false;
        }
    }
}
